"""
用户中心方法
"""
from common.base import Base, get_driver
from selenium.webdriver.common.by import By


class UserCenter(Base):
    def user(self, user):
        self.send_keys((By.NAME, "username"), user)

    def password(self, word):
        self.send_keys((By.NAME, "password"), word)

    def login(self):
        self.click((By.NAME, "submit"))

    # 点击我的订单
    def click_indent(self):
        self.click((By.LINK_TEXT, "我的订单"))

    # 返回第一个订单的订单号
    def order_num(self):
        return self.get_element_text((By.CLASS_NAME, "f6"))

    # 返回订单状态信息
    def order_status(self):
        return self.get_element_text((By.XPATH, "/html/body/div[6]/div[2]/div/div/div/table/tbody/tr[1]/td[4]"))


if __name__ == '__main__':
    driver = get_driver()
    user_center = UserCenter(driver)
    user_center.get("http://localhost:8080/ecshop/user.php")
    user_center.user("root123456")
    user_center.password("root123456")
    user_center.login()
    user_center.click_indent()
    user_center.order_num()
    user_center.order_status()
    user_center.quit(2)
